package com.admin.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author 吴驰明
 * @date 2023/7/18
 * @Description RSA解密
 */
@Component
public class RsaUtils {
    private static final String KEY = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALceXp/FYBjfvbBA" +
            "HYr1dVhBZU0GVibkJ2Ucd0//llruYCudsPNtbjZCxcTKJ2186vmPDv4eX8fUyhLx" +
            "Xbw8y9fDOqgnuAVeTYGQsGu4Ee9Px5yEkQn7Izr4f2MewgLvGvdoymzExx5/WKcm" +
            "GK1KAiuZUaXABiNyP3BI6HuuZAtZAgMBAAECgYACMYHupf2VrrBl+Q6hiHkkWnwt" +
            "JQNJKfhy1Jl1Qtl5M1vBif0BnXDxg3E8/zLjs9hYrub+Ej0RdrII8g0uYQgMA2Gr" +
            "E9uzMEpI9B6JzPJOgDArK8WXRd9cM+1k5yg7b1u/3W2gA+jL20xHucRBuCkC9uHu" +
            "O3ea+2EAGWurPY4d9QJBANuP8IbjAE2phaldEFOQoyMViSBNtocFlo7JqRiQpfGo" +
            "gb5PAEoUvHHUQPPpaaHEgR+9JiHqpgDg4wh0SP6HZKcCQQDVgiEeIfeykKnqwKGs" +
            "3hgpN1bqsyswus4P1WpFvbm9d+5FOg5iTLYo3b81xxNBmj3pzDoGhFo6QwCPH4TL" +
            "dw//AkAV7HmH/oK5PoQqNTC8J2Uiy7O1lgzzzosKFvjbixYG21yZNCpDO27VruwN" +
            "bvEtRgHeuXRlTpjk3Y/N+E6Rm9NhAkB/7ayyRWAJGiz1f95fmeOYLpRhpGEonYWC" +
            "bzlx+DAmmoml6RddRuGOsu8y5clf8W9PexL5fKwjZKodF6GV2A05AkBIss0L/gDJ" +
            "BUgEMbIGNKTcfWObJl4Uv+SKcP+qUbDIIsa6Sq0z8CnzkUMQAVVLJixDO0uV/Oq6" +
            "cWA8pWnTzBDl";
    public static String decrypt(String content) {
        RSA rsa = new RSA(KEY, null);
        byte[] bytes = rsa.decrypt(content, KeyType.PrivateKey);
        return StrUtil.str(bytes, StandardCharsets.UTF_8);
    }
}
